home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1986 August / Ahoy_Magazine_86-08_1986_Double_L.d64 / The Integrator (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  2KB  |  73 lines

  1. 10 print"[147]":poke53280,6:poke53281,1:poke646,0
  2. 20 rem       the integrator
  3. 30 rem      rupert report #32
  4. 40 rem
  5. 50 false=0 : true=not false
  6. 60 c128=false :if ds$<>"" then c128=true
  7. 70 n=5 :rem initial number of intervals
  8. 80 gosub 190 :rem  define function  and  specify limits
  9. 90 rem = = = = =  main loop  = = = = =
  10. 100 if c128 then gosub 260   :rem  plot  function - (c128 only)
  11. 110 gosub 350 :rem integrate function
  12. 120 gosub 480 :rem show results
  13. 130 gosub 530 :rem get # of intervals
  14. 140 if not fini then 100
  15. 150 rem - change next line for desired            default graphics mode -
  16. 160 if c128 then (NULL) 5
  17. 170 end
  18. 180 rem = = = = = = = = = = = = = = = =
  19. 190   rem = define function & limits =
  20. 200 def fna(x) = sqr(r*r-x*x)
  21. 210 r=150  : rem circle of radius 150
  22. 220 x0=0 : x1=r  :rem integration limits
  23. 230 ss=1         :rem  graph step size
  24. 240 dx=(x1-x0)/n :rem  interval size
  25. 250 return
  26. 260   rem = set up & draw function =
  27. 270 (NULL) 2,1,22
  28. 280 (NULL) 1,10,0 to 10,170 to 320,170 :   rem  draw axes
  29. 290 for x=x0 to x1 step ss
  30. 300 y=fna(x)
  31. 310 xp=10+x : yp=170-y
  32. 320 (NULL) 1,xp,yp
  33. 330 next
  34. 340 return
  35. 350   rem = integrate function =
  36. 360 s0=sum : sum=0
  37. 370 for kk=.5 to n
  38. 380 x=x0+dx*kk
  39. 390 y=fna(x)
  40. 400 area=y*dx
  41. 410 sum=sum+area
  42. 420 if not c128 then 460
  43. 430 xu=12+x-dx/2 : yu=170-y
  44. 440 xl=10+x+dx/2 : yl=170
  45. 450 (NULL) 1,xu,yu,xl,yl,0,1
  46. 460 next
  47. 470 return
  48. 480   rem  = show results =
  49. 490 if n0=0 or not c128 then 510
  50. 500 print"intervals :" n0 " area :" s0
  51. 510 print"intervals :" n  " area :" sum
  52. 520 return
  53. 530   rem = update number of intervals =
  54. 540 n0=n
  55. 550 input"how many intervals (0 to stop)";n
  56. 560 if n<1 then fini=true : goto 580
  57. 570 dx=(x1-x0)/n
  58. 580 return
  59. 590 rem  =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
  60. 600 rem  high-res c128 graphics screen            dump to epson mx-80 printer
  61. 610 rem   (when program is done, type                     run 1000)
  62. 1000 e$=chr$(27) : n1=200 : n2=0
  63. 1010 open222,4 : print#222,e$"a"chr$(8)
  64. 1020 for col=0 to 39
  65. 1030 for row=24 to 0 step -1
  66. 1040 m=8192+8*col+320*row
  67. 1050 for lne=7 to 0 step -1
  68. 1060 a$=a$+chr$(peek(m+lne))
  69. 1070 next lne : next row
  70. 1080 print#222,e$"k"chr$(n1)chr$(n2)a$
  71. 1090 a$="" : next col
  72. 1100 print#222 : close222 :end
  73.